<template>
	<!-- 扫码支付押金 -->
	<view class="box" :style="{'--color':vuex_config.themeColor1}">
		<view class="input_box">
			<view class="sign">¥</view>
			<input class="input_view" type="digit" v-model="price" />
		</view>
		<sww-login></sww-login>
		<view class="fix_bot_main">
			<view class="fixed_bottom_btn">
				<view class="word" @click="goPay">立即支付</view>
			</view>
		</view>
	</view>
</template>

<script>
	import { wxConfig } from '@/mixins/wxConfig';
	import { payOrder } from '@/mixins/payOrder.js';
	export default {
			mixins: [payOrder, wxConfig],
		data() {
			return {
				price: 100,
				depositInfo:{},
				type:'押金'
			}
		},
		onLoad(option) {
			// #ifdef H5
			this.initWxConfig(['chooseWXPay'])
				.then(() => {})
				.catch(() => {});
			// #endif
			this.$login('$initPage', null, ).then(() => {
				if(option.type){
					this.type = option.type
				}
				this.$initPage()
			})
		},
		methods: {
			$initPage() {
				// this.$resPost('GetUsersDepositInfo', {
				// 	page: 1,
				// 	page_size: 1
				// }).then(({
				// 	data
				// }) => {
				// 	if (data[0]) {
				// 		this.depositInfo = {
				// 			...data[0]
				// 		};
				// 	}
				// 	this.$hide();
				// }).catch(() => {
				// 	this.$hide();
				// })
			},
			goPay() {
				if(!this.price || this.price <= 0){
					this.$toast('请输入需要缴纳的金额')
					return
				}
				this.$login('$initPage').then(() => {
					this.$resPost('AddAuctionDeposit', {
							price: this.price,
							business_appid: this.vuex_business.appid,
							type:this.type
						})
						.then(res => {
							let pay_type = 1
							// #ifdef MP-ALIPAY
							pay_type = 7
							// #endif 
							// #ifdef MP-BAIDU
							pay_type = 8
							// #endif
							// #ifdef MP-TOUTIAO
							pay_type = 9
							// #endif
							let opts = {
								prodName: this.vuex_business.name,
								totalPrice: this.price, // 支付金额
								remark: '购买保证金', // 余额扣款备注
								updateApi: 'UpdateAuctionDepositStatus', // 更新接口
								pay_type: pay_type,
								redirectUrl: ''
							};
							this.judgeTypeToPay({
									order_no: res.data.order_no
								}, opts)
								.then(() => {
									this.$toast('支付成功');
									setTimeout(() => {
										this.$hide();
										this.$linkTo('index')
									}, 1000);
								})
								.catch(err => {
									if (err) {
										this.$toast({
											title: err
										});
									}
									this.$hide();
								});
						})
						.catch(() => {});
				})
			}
		}
	}
</script>

<style>
	page {
		background-color: #fff;
	}
</style>
<style scoped lang="scss">
	.box {
		padding: 30rpx 50rpx 0;

		.input_box {
			align-items: flex-start;
			display: flex;
			padding-bottom: 10rpx;
			border-bottom: 2rpx solid #f5f5f5;
		}

		.sign {
			font-weight: bold;
			font-size: 50rpx;
			margin-right: 20rpx;
		}

		.input_view {
			flex: 1;
			overflow: hidden;
			font-weight: bold;
			font-size: 60rpx;
			height: auto;
		}
	}
</style>
